/* eslint-disable no-console */
const mongoose = require("./mongoServer");
// const { Schema } = mongoose;
const conn = mongoose.connection;
conn.on("error", () => console.log("连接数据库失败"));

const userMes = mongoose.Schema({
  token: { type: String },
  userId: { type: String },
  userName: { type: String },
  acount: { type: String },
  pass: { type: String },
  userImg: { type: String },
  addTime: { type: String }
});

userMes.statics.getUsers = function(acount, pass) {
  if (acount && pass) {
    return this.model("users")
    .findOne({ acount:acount, pass: pass })
    .exec();
  } else if(acount){
	return this.model("users")
	.find({ acount })
	.exec();  
  }
  else {
    return this.model("users")
      .find()
      .exec();
  }
};
// 新增
// floristBM.statics.addFlowers = function(fId) {
//     return this.model('flowers').find({fId}).exec();
// }
// 修改
// floristBM.statics.setFlowers = function(fId) {
//     return this.model('flowers').find({fId}).exec();
// }
// 删除
// floristBM.statics.dleFlowers = function(fId) {
//     return this.model('flowers').find({fId}).exec();
// }

const model = mongoose.model("users", userMes);
module.exports = model;
